package com.lanou.controller;

import com.github.pagehelper.PageInfo;
import com.lanou.entity.PsychReply;
import com.lanou.service.PsychReplyService;
import com.lanou.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@RestController
@RequestMapping("psychreply")
public class PsychReplyController {
    @Autowired
    private PsychReplyService psychReplyService;
    @GetMapping("{id}")
    public R getPsychReply(@PathVariable Integer id) {
        List<PsychReply> replyList = psychReplyService.selectByPsychId(id);
        return R.ok(replyList);
    }
    @PostMapping
    public R addPsychReply(@RequestBody PsychReply psychReply) {
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String formattedTime1 = now.format(formatter1);
        psychReply.setReplyTime(formattedTime1);
        int i = psychReplyService.insertPsychReply(psychReply);
        return R.ok(i);
    }
    @GetMapping("getid")
    public R getUserId(@RequestParam Integer id,@RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum,
                       @RequestParam(value = "pageSize",required = false,defaultValue = "6") Integer pageSize) {
        PageInfo<PsychReply> psychReplyPageInfo = psychReplyService.selectPsychById(id, pageNum, pageSize);
        return R.ok(psychReplyPageInfo);
    }
    //根据回复内容查询
    @GetMapping("page")
    public R getPsychReplyByReplyContent(PsychReply psychReply,
                                         @RequestParam (required = false,defaultValue = "1") Integer pageNum,
                                         @RequestParam (required = false,defaultValue = "5") Integer pageSize){
        PageInfo<PsychReply> psychReplyPageInfo = psychReplyService.selectPsychByReplyContent(psychReply, pageNum, pageSize);
        return R.ok(psychReplyPageInfo);

    }
}
